package com.dubito.lucene.analyzer;

import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.TokenStream;
import org.apache.lucene.analysis.cn.smart.SmartChineseAnalyzer;
import org.apache.lucene.analysis.tokenattributes.CharTermAttribute;
import org.apache.lucene.analysis.util.CharArraySet;
import org.apache.lucene.util.Version;
import org.wltea.analyzer.lucene.IKAnalyzer;

import java.io.IOException;
import java.io.StringReader;

/**
 * @author liliang
 * @description:
 * @date 2018/4/28.
 */
public class ThirdAnalyzerTest {

    private static final String str = "but and or that 天天要吃饭上班,买车,买房 李天明";

    public static void main(String[] args) throws IOException {
        // 创建分词器
        Analyzer analyzer = new IKAnalyzer();
        // 分词
        TokenStream tokenStream = analyzer.tokenStream(null, new StringReader(str));
        // 迭代
        while (tokenStream.incrementToken()) {
            CharTermAttribute term = tokenStream.getAttribute(CharTermAttribute.class);
            System.out.println(term);
        }
        tokenStream.close();
    }
}
